#include<iostream>
#include"Log.hpp"
#include"TcpServer.hpp"
#include"ThreadPool.hpp"
#include"Command.hpp"
#include"Dict.hpp"

using namespace ThreadPoolModule;

//测试
std::string defaulthandle(const std::string &message)
{
    LOG(LogLevel::DEBUG)<<"回调到了defaulthandle";
    std::string hello = "hello ,";
    hello+=message;
    return hello;
}

//using task_t = std::function<void()>;

void Usage(const std::string proc)
{
    std::cerr<<"Usage: "<<proc<<"port"<<std::endl;
}

//./udpserver port
int main(int argc, char* argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(USEAGE_ERR);
    }

    uint16_t port = std::stoi(argv[1]);
    Enable_Console_Log_Strategy();

    // //1.翻译模块
    // Dict d;
    // d.LoadDict();
    
    //2.命令执行模块
    Command cmd;
    //2.网络服务对象提供通信功能
    std::unique_ptr<TcpServer> servc = std::make_unique<TcpServer>(port,[&cmd](const std::string& command,InetAddr& addr){
       return cmd.Excute(command,addr);
    });

    // std::unique_ptr<TcpServer> servc = std::make_unique<TcpServer>(port,[&d](const std::string &word,InetAddr& addr){
    //     return d.Translate(word,addr);
    // });
    servc->Init();
    servc->Start();
    return 0;
}

// int main()
// {
//     Enable_Console_Log_Strategy();

//     std::unique_ptr<UdpServer> userv = std::make_unique<UdpServer>();
//     userv->Init();
//     userv->Start();

//     return 0;
// }